	$(function(){
		
		$(".products").on("click","#all",function(){
			if($("#all").get(0).checked){
				$(":checkbox[name='checked']").attr("checked",true);
			}else{
				$(":checkbox[name='checked']").attr("checked",false);	
			}
		});
/*
		$("#all").click(function(){
			if($("#all").get(0).checked){
				$(":checkbox[name='checked']").attr("checked",true);
			}else{
				$(":checkbox[name='checked']").attr("checked",false);	
			}
		});
*/	
//$(":checkbox[name='checked']").click(function(){
	$(".products").on("click",":checkbox[name='checked']",function(){
				if($("#all").get(0).checked){
					$("#all").attr("checked",false);
				}
				if(!$("#all").is(":checked") && $(":checkbox[name='checked'][checked='checked']").length==($(":checkbox[name='checked']").length)){
						$("#all").attr("checked",true);	
					}
		});
		
	});
	$("#order").click(function(){
		if($(":checkbox[name='checked'][checked='checked']").length==0){
			alert("请选择要购买的商品");
		return ;
		}else{
			$("form[action='submit']").submit();			
		}
		
	});
	$("#myorder").click(function(){
		/*
		var userId = $("#userId").val();
		if(userId == "" || userId == null){
			return false;
		}else{
			$("form[action='loaduserorders']").submit();
		}
			*/
		$("form[action='loaduserorders']").submit();
	});
	$("#cover").click(function(){
		window.location.href="http://localhost:8080/shoppingcart/cart/reloadgoods";
	});
	$("#delete").click(function(){
		if($(":checkbox[name='checked'][checked='checked']").length==0){
			alert("请选择要删除的商品");
			return ;
		}
		if($(":checkbox[name='checked'][checked='checked']").length==($(":checkbox[name='checked']").length)){
			alert("您不能删除所有商品");
			return ; 
		}
	var checkItem = $(":checkbox[name='checked'][checked='checked']");
	var itemids = new Array();
	$.each(checkItem, function(i, n){
		 itemids[i] = n.value;
		});
	$.ajax({
			url : "delete",
			type : "post",
			data :{
				"checked":itemids
			},
			dataType :"json",
			success : function(result){
				$(".products #goods").empty();
				$(".products #goods").append(
						"<tr>"+
						"<th><input id=\"all\" type=\"checkbox\"/></th>"+
						"<th>商品编号</th>"+
						"<th>商品名称</th>"+
						"<th>单价</th>"+
						"<th>数量</th>"+
						"<th>是否热销</th>"+
						"<th>店铺</th>"+
						"</tr>");
				for(var i=0;i<result.length;i++){
					var onsale ="";
					if(result[i].hot==true){
						onsale="是";
					}else{
						onsale="否";
					}
					$(".products #goods").append(
							"<tr>"+
							"<td><input name=\"checked\" type=\"checkbox\" value=\""+result[i].pId+"\"></td>"+
							"<td>"+result[i].pId+"</td>"+
							"<td>"+result[i].pname+"</td>"+
							"<td>"+result[i].price+"</td>"+
							"<td>"+result[i].amount+"</td>"+
							"<td>"+onsale+"</td>"+
							"<td>"+result[i].saler+"</td>"+
							"</tr>");
				}
			},
			error :function(){
				alert("服务器繁忙");
			}
		});
	});